package com.javalong.affairs.activity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;

import com.javalong.affairs.R;
import com.javalong.affairs.adapter.GranterAdapter;
import com.javalong.affairs.constant.BundleKey;
import com.javalong.affairs.constant.DataType;
import com.javalong.affairs.constant.MapKey;
import com.javalong.affairs.data.AllData;
import com.javalong.affairs.model.User;
import com.javalong.affairs.ui.SimplePullRefreshList;
import com.javalong.affairs.ui.TopTitle;
import com.javalong.affairs.ui.TopTitle.OnRightTextClick;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_granter)
public class GranterActivity extends BaseActivity implements OnRightTextClick {
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.lv_granter)
	private SimplePullRefreshList lv_granter;

	private GranterAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		topTitle.setOnLeftDrawableClick(this);
		List<User> userList = AllData.GetInstance().appendListData(
				R.string.data_granter_list, new ArrayList<User>());
		adapter = new GranterAdapter(this, userList);
		lv_granter.setAdapter(adapter);
		lv_granter.initData(getMapData());
		lv_granter.refresh();
		topTitle.setOnRightTextClick(this);

	}

	private Map<String, Object> getMapData() {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put(MapKey.ACTION_NAME, "Journal");
		param.put(MapKey.METHOD_NAME, "outList_journal ");
		param.put(MapKey.DATA_RESID, R.string.data_granter_list);
		param.put(MapKey.DATA_TYPE, DataType.LIST_USER);
		return param;
	}

	@Override
	public void rightTextClick() {
		Intent intent = new Intent();
		intent.putExtra(BundleKey.USERLIST,
				(Serializable) adapter.getSelectedUsers());
		setResult(RESULT_OK, intent);
		finish();
	}
}
